﻿@using Orchard.ContentManagement
@using Orchard.DynamicForms.Elements
@using Orchard.Layouts.Helpers
@{
    Style.Include("DynamicForms.css", "DynamicForms.min.css");
}
@{
    var contentItem = (ContentItem) Model.ContentItem;
    var element = (Form) Model.Element;
    var tagBuilder = TagBuilderExtensions.CreateElementTagBuilder(Model);
    var formName = element.Name;
    var processedAction = (string)Model.ProcessedAction;
    var formAction = String.IsNullOrWhiteSpace(processedAction) ? Url.Action("Submit", "Form", new { area = "Orchard.DynamicForms"}) : processedAction;
    var formMethod = !String.IsNullOrWhiteSpace(element.Method) ? element.Method : "POST";
    
    tagBuilder.AddCssClass("dynamic-form");

    if (element.EnableClientValidation == true) {
        Script.Require("jQuery").AtFoot();
        Script.Include("Lib.js", "Lib.min.js").AtFoot();

        Html.EnableUnobtrusiveJavaScript();
        Html.EnableClientValidation();
    }
}
@tagBuilder.StartElement
<form action="@formAction" method="@formMethod" enctype="multipart/form-data">
    @DisplayChildren(Model)
    <input type="hidden" name="formName" value="@formName" />
    <input type="hidden" name="contentId" value="@contentItem.Id" />
    @Html.AntiForgeryToken()
</form>
@tagBuilder.EndElement